package com.mfc.education.service.statistics.controller.admin;


import com.mfc.education.common.base.result.R;
import com.mfc.education.service.statistics.feign.UcenterMemberService;
import com.mfc.education.service.statistics.service.DailyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 网站统计日数据 前端控制器
 * </p>
 *
 * @author Mfc
 * @since 2021-10-05
 */
@Api(description = "统计分析管理")
@RestController
@RequestMapping("/admin/statistics/daily")
@Slf4j
public class DailyController {

    @Autowired
    private DailyService dailyService;

    @ApiOperation("生成统计记录")
    @PostMapping("create")
    public R getStatistics(@ApiParam(value = "统计日期",required = true)
                                       @RequestParam("day") String day){

        dailyService.createStatisticsByDay(day);

        return R.ok().message("数据统计生成成功");
    }


    @ApiOperation("显示统计数据")
    @GetMapping("show-chart/{begin}/{end}")
    public R showChart(@ApiParam("开始时间") @PathVariable String begin,
                       @ApiParam("结束时间") @PathVariable String end){
        Map<String,Map<String, Object>> map =  dailyService.getChartData(begin,end);
        return R.ok().data("chartData",map);
    }

}

